package edu.mobbuzz.web.pages;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.Retain;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import edu.mobbuzz.daf.bean.User;
import edu.mobbuzz.daf.dao.IUserDao;
import edu.mobbuzz.web.base.SecureBasePage;

public class UserGridPage extends SecureBasePage{
	@Inject
	private IUserDao userDao;
	
	private List<User> userList;
	@Property
	private User user;
	
	@Retain
	private BeanModel userModel;
	@Inject
	private BeanModelSource beanModelSource;
	@Inject
	private ComponentResources resources;
	
	public IUserDao getUserDao() {
		return userDao;
	}
	
	public BeanModel getUserModel() {
		return userModel;
	}	
	
	public List<User> getUserList() {
		if(userList==null){
			userList = new ArrayList<User>();
		}
		userList = getUserDao().queryForList("", "");		
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	void pageLoaded(){
		userModel = beanModelSource.createDisplayModel(User.class, resources.getMessages());
	
	}
}
